package HouseTest.dao;


import HouseTest.javaBean.Admin;
import HouseTest.javaBean.House;
import org.apache.ibatis.session.SqlSession;

import java.io.IOException;
import java.util.ArrayList;
public class HouseDao {

    public ArrayList<House> findList() throws IOException {
        SqlSession sqlSession = ThingManage.startThing();
        FindHouseData mapper = sqlSession.getMapper(FindHouseData.class);
        return mapper.findAllHouse();
    }
    /**
     * 查找房屋
     * @param num
     * @return
     * @throws IOException
     */
    public House findDAao(int num) throws IOException {

        SqlSession sqlSession = ThingManage.startThing();
        FindHouseData mapper = sqlSession.getMapper(FindHouseData.class);
        House house1= mapper.findHouse(num);
        if(house1!=null){
            return house1;
        }
        return null;
    }
    /**
     * 删除房屋
     * @param m
     * @throws IOException
     */
    public void deleteOneHouse(int m) throws IOException {
        SqlSession sqlSession = ThingManage.startThing();
        FindHouseData mapper = sqlSession.getMapper(FindHouseData.class);
        mapper.delete(m);
        sqlSession.commit();
    }

    /**
     * 更新房屋信息
     * @param house
     * @throws IOException
     */

    public void revise(House house) throws IOException {

        SqlSession sqlSession = ThingManage.startThing();
        FindHouseData mapper = sqlSession.getMapper(FindHouseData.class);
        mapper.updateOneHouse(house);
        sqlSession.commit();
    }

    /**
     * 添加房屋
     * @param house
     * @throws IOException
     */
    public void insertHouse(House house) throws IOException {
        SqlSession sqlSession = ThingManage.startThing();
        FindHouseData mapper = sqlSession.getMapper(FindHouseData.class);
            mapper.insertHouse(house);
            sqlSession.commit();
    }

    public Admin isAdmin(Admin admin) throws IOException {
        SqlSession sqlSession = ThingManage.startThing();
        FindHouseData mapper = sqlSession.getMapper(FindHouseData.class);
        return mapper.isAdmin(admin);
    }
}
